package com.tbit.uqbike.object.pojo.vo;

import com.tbit.uqbike.annos.Excel;
import com.tbit.uqbike.constant.FaultType;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * @Author LHX
 * @ClassName MachinefaultlogVo
 * @Description
 * @date 2023/5/18 15:48
 * @Version 1.0
 */
@Data
public class MachineFaultLogVo {

    /**
     * 车辆编号
     */
    @Excel(name = "车辆编号", sort = 0)
    private String userCode;

    /**
     * 故障类型
     */
    private String faults;

    /**
     * 故障类型名称
     */
    @Excel(name = "故障类型", sort = 1)
    private String faultsName;

    /**
     * 说明
     */
    @Excel(name = "描述", sort = 2)
    private String remark;

    /**
     * 图片
     */
    private String imageIds;

    /**
     * 上报人id
     */
    private Integer addManid;

    /**
     * 上报人姓名
     */
    @Excel(name = "上报人姓名", sort = 3)
    private String addManName;

    /**
     * 联系方式
     */
    @Excel(name = "上报人联系方式", sort = 4)
    private String addManPhone;

    /**
     * 上报时间
     */
    @Excel(name = "上报时间", sort = 5)
    private String addTime;
    /**
     * 0运维1用户
     */
    private Integer intoMain;

    @Excel(name = "处理进度", sort = 6, readConverterExp = "0=待维修,1=待维修,2=待维修,3=维修中,4=已经处理,5=待核实")
    private Integer faulttype;

    @Excel(name = "故障编号", sort = -1)
    private String orderNO;

    private String userPhone;

    /**
     * 操作时间
     */
    @Excel(name = "操作时间", sort = 7)
    private String operationTime;

    /**
     * 操作类型
     */
    @Excel(name = "操作类型", sort = 8)
    private String operationType;

    /**
     * 故障/维修类型
     */
    @Excel(name = "故障/维修类型", sort = 9)
    private String repairType;

    /**
     * 描述
     */
    @Excel(name = "描述", sort = 10)
    private String handleDescribe;

    /**
     * 图片
     */
    @Excel(name = "图片", sort = 11)
    private String handlePhoto;

    /**
     * 操作人
     */
    @Excel(name = "操作人", sort = 12)
    private String operationName;

    /**
     * 联系方式
     */
    @Excel(name = "联系方式", sort = 13)
    private String operationPhone;


    public void parseFaults() {
        if (StringUtils.isBlank(faults)) {
            return;
        }
        if (intoMain == 1 || intoMain == 2) {
            faultsName = faults;
            return;
        }

        //维修：上传维修记录 重新进行转换
        int repair = 3;
        if (this.faulttype == repair) {
            this.faultsName = FaultType.matchFaultType(this.faults);
            return;
        }
        faultsName = FaultType.parseFaults(this.faults);
    }

    /**
     *  解析维修类型
     */
    public void analysis(){
        StringBuilder type = new StringBuilder();
        if (Objects.isNull(this.repairType)){
            return;
        }
        String[] list = this.repairType.split(",");
        if (list.length > 0){
            for (String s : list) {
                switch (s){
                    case "0":
                        type.append("转把手").append(",");
                        break;
                    case "1":
                        type.append("车灯").append(",");
                        break;
                    case "2":
                        type.append("线路").append(",");
                        break;
                    case "3":
                        type.append("车篮").append(",");
                        break;
                    case "4":
                        type.append("车轮").append(",");
                        break;
                    case "5":
                        type.append("车撑").append(",");
                        break;
                    case "6":
                        type.append("刹车").append(",");
                        break;
                    case "7":
                        type.append("车座").append(",");
                        break;
                    case "8":
                        type.append("二维码").append(",");
                        break;
                    case "9":
                        type.append("电池").append(",");
                        break;
                    case "10":
                        type.append("脚蹬").append(",");
                        break;
                    case "11":
                        type.append("前叉").append(",");
                        break;
                    case "12":
                        type.append("挡泥板").append(",");
                        break;
                    case "13":
                        type.append("控制器").append(",");
                        break;
                    case "14":
                        type.append("中控").append(",");
                        break;
                    case "15":
                        type.append("响铃铛").append(",");
                        break;
                    case "16":
                        type.append("电池锁").append(",");
                        break;
                    //兼容ios和安卓
                    case "17":
                    case "50":
                        type.append("其他").append(",");
                        break;
                    default:
                        break;
                }
            }
        }
        String s = type.toString();
        if (StringUtils.isNotBlank(s) && s.endsWith(",")) {
            s = s.substring(0, s.length() - 1);
        }
        this.repairType = s;
    }


}
